package com.boolib.shopadmin.config.shiro.filter;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.filter.AccessControlFilter;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Slf4j
public class MyFormFilter  extends FormAuthenticationFilter {

//    @Autowired
//    IUserService iUserService;
//
//    @Autowired
//    UserMapper userMapper;

    @Override
    protected boolean onLoginSuccess(AuthenticationToken token, Subject subject, ServletRequest request, ServletResponse response) throws Exception {



        subject.getSession().setAttribute(subject.getSession(),token.getPrincipal());

        HttpServletResponse response1 = ((HttpServletResponse) response);

        HttpServletRequest request1 = ((HttpServletRequest) request);


        //request1.setAttribute("msg",   iUserService.getMenus());

        request1.getRequestDispatcher("/index").forward(request1,response);


        return true;
    }



}
